#include "TimeStamp.h"

#include <algorithm>
#include <sys/time.h>




TimeStamp::TimeStamp() :
    microSecondsSinceEpoch_(0)
{

}

TimeStamp::TimeStamp(int64_t microSecondsSinceEpoch) :
    microSecondsSinceEpoch_(microSecondsSinceEpoch)
{

}

TimeStamp TimeStamp::addTime(TimeStamp t1, double seconds) {
    return TimeStamp(t1.microSecondsSinceEpoch_ + seconds * kMicroSecondsPerSecond);
}

void TimeStamp::swap(TimeStamp& rhs) {
    std::swap(microSecondsSinceEpoch_, rhs.microSecondsSinceEpoch_);
}

TimeStamp TimeStamp::now() {
    timeval tv;
    gettimeofday(&tv, NULL);
    return TimeStamp(tv.tv_sec * kMicroSecondsPerSecond + tv.tv_usec);    
}